package com.manager.service;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import org.jorm.Session;

public class ServiceUtil {

	private Session session;

	public ServiceUtil(Session session) {
		this.session = session;
	}

	public int getNextId(String table, String column) {
		int nextId = 0;
		try {
			Connection connection = session.connection();
			String sql = "select max(" + column + ")+1 as nextId from " + table;
			PreparedStatement ps = connection.prepareStatement(sql);
			ResultSet rs = ps.executeQuery();
			if (rs.next()) {
				nextId = rs.getInt(1);
			}
			rs.close();
			ps.close();
			// session.getSessionFactory().getConnectionProvider().closeConnection(connection);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return nextId;
	}
}
